package com.gym.code.generator.impl.dao.sql.impl;

import java.util.ArrayList;
import java.util.List;

import com.gym.code.generator.impl.dao.sql.WhereSqlGenerator;
import com.gym.code.generator.model.mapping.field.ParameterFieldGenerateModel;
import com.gym.code.generator.model.mapping.method.MethodDeleteModel;

/**
 * 
 * @author xinchun.wang 
   @email: 532002108@qq.com
 * @createTime 2015-4-15 下午8:21:45
 */
public class DeleteSqlGenerator extends WhereSqlGenerator<MethodDeleteModel> {

    private static DeleteSqlGenerator instance = new DeleteSqlGenerator();
	public static DeleteSqlGenerator getInstance(){
		return instance;
	}
	private DeleteSqlGenerator(){}
	
	
	@Override
	public String generate(MethodDeleteModel methodModel) {
		
		StringBuilder sqlBuilder = new StringBuilder();
		sqlBuilder.append("delete from  ").append(methodModel.getBeanGenerateModel().getTableName());
		sqlBuilder.append(" where 1 = 1 ");
		sqlBuilder.append(generateWhereColumn(methodModel.getParameterList()));
		return sqlBuilder.toString();
	}
	
	protected String generateWhereColumn(List<ParameterFieldGenerateModel> parameterList){
		List<ParameterFieldGenerateModel> whereParam = new ArrayList<ParameterFieldGenerateModel>();
		for(ParameterFieldGenerateModel item : parameterList){
			whereParam.add(item);
		}
		return super.generateWhereColumn(whereParam);
	}
	
}



